#!/bin/bash
ProPath=$(cd `dirname $0`; pwd)
Time=`date +%Y%m%d_%H%M%S`
SYS_INFO=`uname -r`

echo "sys info "$SYS_INFO

PRONAME_FTP=""
PRONAME=""
SYS_INFO=${SYS_INFO#*-}
SYS_INFO=${SYS_INFO:0:4}
if [ $SYS_INFO"rr" == "Gn64rr" ];then
PRONAME=$PRONAME"_gnos"
fi

function  check_program_status()
{
	echo "check "$1 "; path:"$2 ":tail info:"$3
	check_proc=$1
	ProInfo=`ps -ef | grep $check_proc|grep -v grep|wc -l`
	echo $ProInfo
	if [ $ProInfo -le 0 ];then

		ProInfo1=`ps -ef | grep $check_proc| grep -v grep|wc -l`
		echo $ProInfo1
		if [ $ProInfo1 -le 0 ];then
			cd $2
			./run.sh
			echo "reboot :"$2/$check_proc ";time = "$Time >>$ProPath/hdas_monitor.log
		fi
	fi
}

#monitor  app 
check_program_status  hddp  $ProPath/hddp  	$PRONAME
check_program_status  huas_gnos  $ProPath/huas	$PRONAME
check_program_status  fe_gnos  	$ProPath/fe  	$PRONAME
check_program_status  fe_http_statistics_gnos  $ProPath/fe_http_statistics	$PRONAME

##monitor  ftp upload
check_program_status  data_push_ad_log  $ProPath/fe/dataPush_ad_log_ftp  	$PRONAME_FTP
check_program_status  data_push_huas_log  $ProPath/huas/dataPush_huas_ftp	$PRONAME_FTP
check_program_status  data_push_http_log  $ProPath/dataPush_http_log_ftp/dataPush_http_log_ftp	 $PRONAME_FTP
